import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/less/index.less'
import App from './App'
import router from './router'
import store from './store'
import { purifyParams, setMoreItems, handleSearch, handleChangePage, apiCreateData, apiEditData, apiDeleteData, handleGetTableData } from '@/config/utils'
import { authBtns } from '@/config/permission'
import systemObj from './config/system'
import { dialogBtn } from '@/config/defaultBtnData'
import 'vue-admin-ui-lib/lib/style/index.css'
import { adminMethods, searchModule, tableModule, dialogModule } from 'vue-admin-ui-lib'

import { formatDate } from 'vue-admin-methods'

Vue.use(ElementUI)
  .use(searchModule)
  .use(tableModule)
  .use(dialogModule)

Vue.directive('btn', {
  inserted (el, val) {
    const { value } = val
    const btnName = value && authBtns.getBtnName(value)
    if (!btnName && el.parentNode) {
      el.parentNode.removeChild(el)
    }
  }
})

Vue.prototype.$purifyParams = purifyParams
Vue.prototype.$format = formatDate
Vue.prototype.$getBtnName = authBtns.getBtnName.bind(authBtns)
Vue.prototype.$getAuthBtns = authBtns.getConfigBtns.bind(authBtns)
Vue.prototype.$InitObj = adminMethods.onCreateBasicData({ defaultDialogBtn: dialogBtn })
Vue.prototype.$setMoreItems = setMoreItems
Vue.prototype.$setItem = adminMethods.setItemProp
Vue.prototype.$systemObj = systemObj
Vue.prototype.$handleSearch = handleSearch
Vue.prototype.$handleGetTableData = handleGetTableData
Vue.prototype.$apiCreateData = apiCreateData
Vue.prototype.$handleChangePage = handleChangePage
Vue.prototype.$apiEditData = apiEditData
Vue.prototype.$apiDeleteData = apiDeleteData
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
